--
-- Author: gnar
-- Date: 2015-12-30 09:04:09
--
local ActNames = import(".ActNames")
local ManagerRes = class("ManagerRes")
local gInstance = nil


local set1 = {
	common_1 = "c1",
	common_2 = "c2",
	common_3 = "c3",
	common_4 = "c4",
	common_5 = "c5",
	[ActNames[1]] = "wf",
	[ActNames[2]] = "wl",
	[ActNames[3]] = "wr",
	[ActNames[4]] = "wb",
	[ActNames[5]] = "wfl",
	[ActNames[6]] = "wfr",
	[ActNames[7]] = "wbl",
	[ActNames[8]] = "wbr",

	[ActNames[9]] = "if",
	[ActNames[10]] = "il",
	[ActNames[11]] = "ir",
	[ActNames[12]] = "ib",
	[ActNames[13]] = "ifl",
	[ActNames[14]] = "ifr",
	[ActNames[15]] = "ibl",
	[ActNames[16]] = "ibr",

}

function ManagerRes.getInstance()
	if not gInstance then
		gInstance = ManagerRes.new()
	end

	return gInstance
end


function ManagerRes.entityModelsCCBNode(resName)



end

function ManagerRes.getCharacterCCBNode(resName, owner)

	local path = "entityModels/Character/" .. resName .. ".ccbi"
	if not ccb[resName] then ccb[resName] = {} end
	return CCBReaderLoad(path, CCBProxy:create(), owner)

end


-- function ManagerRes.getEntityCCBNode(entityName, owner)

-- 	local path = "entityModels/" .. resName .. ".ccbi"
-- 	if not ccb[resName] then ccb[resName] = {} end
-- 	return CCBReaderLoad(path, CCBProxy:create(), owner)

-- end


function ManagerRes.getCharacterMapAction(imageName, actionName)
	local resPath = "entityModels/Character/" .. imageName

	if not cc.SpriteFrameCache:getInstance():isSpriteFramesWithFileLoaded(resPath .. ".plist") then
		print("test ManagerRes.getCharacterMapAction")
		display.loadSpriteFrames(resPath .. ".plist", resPath .. ".png")  -- 自己管理释放 display.removeUnusedSpriteFrames()
	end

	local animation = ManagerRes.getAniByFramePrefix(set1[imageName] .. "_" .. set1[actionName] .. "_")

	return animation
end

function ManagerRes.getAniByFramePrefix(framePrefix)

	local animation = cc.Animation:create()
	for i = 1, 100 do
		local frameName =  framePrefix .. i .. ".png"
		local frame = cc.SpriteFrameCache:getInstance():getSpriteFrame(frameName)
		if frame then
			animation:addSpriteFrame(frame)
		else
			break
		end
	end

	return animation

end
-- function ManagerRes.getEntityMapAction(imageName, actionName)

-- 	local path = "entityModels/" .. resName .. ".ccbi"
-- 	if not ccb[resName] then ccb[resName] = {} end
-- 	return CCBReaderLoad(path, CCBProxy:create(), owner)

-- end







return ManagerRes